package com.lry.basic.juc;

import com.sun.org.apache.xpath.internal.operations.Bool;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/7/15
 */
//         Thread.interrupted();//清除中断标志，并返回清除前的值
//         Thread.currentThread().isInterrupted();//判断中断标志
//         Thread.currentThread().interrupt();//设置中断为true
public class ThreadInterupt {
    //wait sleep join
    public static void main(String[] args) throws InterruptedException {

        Thread t = new Thread(new Runnable() {
            @Override
            public synchronized void run() {
                while(!Thread.currentThread().isInterrupted()){
                    System.out.println("run");
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        System.out.println("catch:"+Thread.currentThread().isInterrupted());
                        Thread.currentThread().interrupt();//再次中断，即可立即退出线程
                    }
//                    try {
//                        Thread.sleep(10000);//发现中断标志flag = true，重置flag = false，响应中断进入catch
//                    } catch (InterruptedException e) {
//                        System.out.println("catch:"+Thread.currentThread().isInterrupted());
//                        Thread.currentThread().interrupt();//再次中断，即可立即退出线程
//                    }
                }
            }
        });
        t.start();
        Thread.sleep(1000);
        t.interrupt();
    }


}
